from openai import OpenAI
import os


def chat(msg: str, model: str) -> str:
	# for backward compatibility, you can still use `https://api.deepseek.com/v1` as `base_url`.
	client = OpenAI(api_key = os.environ.get('DEEPSEEK_API_KEY'), base_url = os.environ.get('DEEPSEEK_BASE_URL'))

	response = client.chat.completions.create(
		model = model,
		messages = [
			# {"role": "system", "content": "You are a helpful assistant"},
			{"role": "user", "content": msg},
		],
		max_tokens = 1024,
		temperature = 0.7,
		stream = False
	)

	return response.choices[0].message.content


def models():
	client = OpenAI(api_key = os.environ.get('DEEPSEEK_API_KEY'), base_url = os.environ.get('DEEPSEEK_BASE_URL'))
	models = []
	for item in client.models.list().data:
		models.append(item.id)
	return models
